package A06_递归;

/**
 *  简单递归应用
 * @Author: KingWang
 * @Date: 2021/6/3
 * @Desc:
 **/
public class RecursionDemo {

    public static void main(String[] args) {

        test(5);
        System.out.println(factorial(5));

    }

    //简单递归
    public static void test(int n){
        if(n > 0 ){
            test(n - 1);
        }
        System.out.println("n:" +n);
    }

    //阶乘问题：5! = 5*4*3*2*1
    public static int factorial(int n){
        System.out.print( n + "*" + (n-1) + " ");
        if(n == 1) {
            return 1;
        }else{
            return factorial(n-1) * n;
        }

    }
}
